﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using KTOP.Core.Domain.Matrix;

namespace KTOP.Homeworks.Hw7.Logics
{
    class MatrixMixer
    {
        public static int[][] Mix(RMatrix rMatrix)
        {
            var matrix = rMatrix.Matrix.Select(m => m.ToArray()).ToArray();
            var remap = new List<int>();
            var random = new Random();
            
            for (var i =0; i< matrix.Length;i++)
            {
                var r = 0;
                while (remap.Contains(r = random.Next(matrix.Length))) ;

                remap.Add(r);
            }

            var dst = Enumerable.Range(0, rMatrix.Size)
                .Select(_ => new int[rMatrix.Size])
                .ToArray();

            for (var row = 0; row < matrix.Length;row++)
            {
                for (var col = 0; col < matrix.Length; col++)
                {
                    dst[remap[row]][remap[col]] = matrix[row][col];
                }
            }

            return dst;
        }

    }
}
